﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using USPCommon.Core.Log;
using System.Web;

namespace SMTC.WebCommon.Common
{
    public class Global:System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup

        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
#if !DEBUG
            PLLog.logPath = Server.MapPath("~");
            Exception objErr = Server.GetLastError().GetBaseException();            
            string strErrorUrl = Request.Url.ToString();
            PLLog.Error(strErrorUrl, objErr);
            try
            {
                Response.Redirect("~/Common/Error.aspx?ErrorMessage=" + objErr.Message.ToString());
            }
            catch (Exception ex)
            {
                PLLog.Error("转向错误页面失败", ex);
            }
#endif
        }

        void Session_Start(object sender, EventArgs e)
        {
            Session.Timeout = 60;
            // Code that runs when a new session is started
#if DEBUG
            SMTC.Model.Model.SMT_UserInfo user = new Model.Model.SMT_UserInfo();
            user.UserName = "admin";
            Session["STMCUser"] = user;
#endif
            if (Session["STMCUser"] == null)
            {
               Response.Redirect( @"~/UserPower/UserLogin.aspx");
            }

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }
    }
}
